package com.neuedu.security.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.neuedu.security.entity.SysMenu;
import com.neuedu.security.service.ISysMenuService;
import com.neuedu.security.vo.SysMenuVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author 金山老师
 * @since 2023-03-15
 */
@RestController
@RequestMapping("/sysMenu")
@Api(tags = "菜单管理")
public class SysMenuController {

    @Autowired
    ISysMenuService sysMenuService;


    /**
     * 查询顶层菜单（一级）
     * @return
     */
    @ApiOperation(value = "查询顶层菜单")
    @GetMapping("/loadTopMenu")
    public List<SysMenu> loadTopMenu(){

        LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysMenu::getParentId,0);
        return sysMenuService.list(queryWrapper);


    }


    /**
     * 查询顶层菜单（一级）
     * @return
     */
    @ApiOperation(value = "查询子菜单")
    @GetMapping("/loadChildrenMenu/{parentId}")
    public List<SysMenu> loadChildrenMenu(@PathVariable(value="parentId")  Integer parentId){

        LambdaQueryWrapper<SysMenu> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(SysMenu::getParentId,parentId);

        return sysMenuService.list(queryWrapper);


    }


    @ApiOperation(value = "根据主键查询菜单")
    @GetMapping("/getById/{id}")
    public SysMenu getById(@PathVariable Integer id) {
        return sysMenuService.getById(id);
    }



    @ApiOperation(value = "菜单添加或修改")
    @PostMapping("/saveOrUpdate")
    public boolean saveOrUpdate(@RequestBody SysMenu menu) {

        return sysMenuService.saveOrUpdate(menu);

    }



    @ApiOperation(value = "菜单根据主键删除")
    @GetMapping("/removeById/{id}")
    public boolean removeById(@PathVariable long id) {
        return sysMenuService.removeById(id);

    }



//    @ApiOperation(value = "加载菜单的树形结构 ，json")
//    @GetMapping("/loadTree")
//    public List<SysMenuVO> loadTree() {
//        return sysMenuService.loadTree();
//
//    }











}
